/* eslint-disable no-plusplus */
const eventClass = require('./../../events/eventClass');

const path_ = eval('require')('path');
const {
    basePath,
    appAsar,
} = require('./../../../../../foreEndApi/rebasePath')();

const {
    spawn,
    exec,
} = eval('require')('child_process');

const toolPath = path_.join((appAsar || basePath), 'third-park', 'gdal');

class gdalClass extends eventClass {
    constructor() {
        super('gdal');
        this.tools = {
            gdalinfo: path_.join(toolPath, 'gdalinfo.exe'),
        };
    }

    gdalinfo(cb, { path }) {
        exec(`${this.tools.gdalinfo} -json ${path}`, (err, stdout, stderr) => {
            if (err) {
                this.returnMethod(cb, { err });
            } else {
                this.returnMethod(cb, {
                    data: {
                        stdout,
                        stderr,
                    },
                });
            }
        });
    }
}

module.exports = gdalClass;
